package com.hospital.payment.module.controller;

import com.hospital.common.base.PageResult;
import com.hospital.common.base.Result;
import com.hospital.common.dto.payment.module.BackendOrderDto;
import com.hospital.common.dto.payment.module.OrderCreateDto;
import com.hospital.common.dto.payment.module.OrderDto;
import com.hospital.common.dto.payment.module.OrderPayDto;
import com.hospital.common.pojo.TPaymentMethod;
import com.hospital.common.validator.payment.module.ValidateGroup;
import com.hospital.common.vo.payment.module.BackendOrderVo;
import com.hospital.common.vo.payment.module.OrderStatVo;
import com.hospital.common.vo.payment.module.OrderVo;
import com.hospital.payment.module.service.TOrderService;
import com.hospital.payment.module.service.TPaymentMethodService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支付服务接口
 * @author yhn
 * @version 1.0
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private TOrderService orderService;
    @Autowired
    private TPaymentMethodService paymentMethodService;

    /**
     * 查询订单(统计接口)
     */

    @PostMapping("/queryForStat")
    public Result<List<OrderVo>> queryForStat(@Validated (ValidateGroup.OrderQueryGroup.ForStat.class) @RequestBody OrderDto orderDto){
        return Result.success(orderService.query(orderDto));
    }

    /**
     * 分页查询订单(非统计接口)
     */

    @PostMapping("/queryInPage")
    public Result<PageResult<OrderVo>> queryInPage(@Validated(ValidateGroup.OrderQueryGroup.InPage.class) @RequestBody OrderDto orderDto){
        return Result.success(orderService.queryInPage(orderDto));
    }

    /**
     * 查询订单(非统计接口)
     */

    @PostMapping("/query")
    public Result<List<OrderVo>> query(@Validated (ValidateGroup.OrderQueryGroup.NotForStat.class)@RequestBody OrderDto orderDto){
        return Result.success(orderService.query(orderDto));
    }

    /**
     * 创建订单
     */

    @PostMapping("/create")
    public Result<?> create(@Validated(ValidateGroup.CreateOnlineDiagnosisOrder.none.class) @RequestBody OrderCreateDto orderCreateDto){
        orderService.create(orderCreateDto);
        return Result.success();
    }

    /**
     * 创建线上诊断订单
     */
    @PostMapping("/createOnlineDiagnosis")
    public Result<?> createOnlineDiagnosis(@Validated(ValidateGroup.CreateOnlineDiagnosisOrder.online.class) @RequestBody OrderCreateDto orderCreateDto){
        orderService.create(orderCreateDto);
        return Result.success();
    }
    /**
     * 查询支付方式
     */
    @GetMapping("/queryPaymentMethod")
    public Result<List<TPaymentMethod>> queryAll(){
        return Result.success(paymentMethodService.queryAll());
    }
    /**
     * 支付
     */
    @PostMapping("/pay")
    public Result<?> pay(@Valid @RequestBody OrderPayDto orderPayDto){
        orderService.pay(orderPayDto);
        return Result.success();
    }
    /**
     * 取消挂号
     * @param patientId 患者ID
     * @param registrationId 挂号ID
     */
    @GetMapping("/cancelRegistration")
    public Result<?> cancelRegistration(@RequestParam("patientId") Long patientId, @RequestParam("registrationId") Long registrationId){
        orderService.cancelRegistration(patientId, registrationId);
        return Result.success();
    }
    /**
     * 患者订单统计
     */
    @GetMapping("/getPatientOrderStat")
    public Result<OrderStatVo> patientOrderStat(){
        return Result.success(orderService.patientOrderStat());
    }
    /**
     * 后台订单统计
     */
    @GetMapping("/getBackendOrderStat")
    public Result<OrderStatVo> backendOrderStat(){
        return Result.success(orderService.backendOrderStat());
    }

    /**
     * 后台分页查询订单
     */
    @PostMapping("/backendQueryInPage")
    public Result<PageResult<BackendOrderVo>> backendQueryInPage(@Valid @RequestBody BackendOrderDto orderDto){
        return Result.success(orderService.backendQueryInPage(orderDto));
    }
}
